const app = new BasicTableVue({
    data() {
        const header = new Map()
            .set('所在机房', 'houseName')
            .set('应用IP', 'ip')
            .set('端口', 'port')
            .set('访问域名', 'domain')
            .set('访问次数', 'accessCount')
            .set('服务内容', 'serviceContent')
            .set('违规情况', 'illegalType')
            .set('处置状态', 'dealStatus')
            .set('处置人', 'operationAccount')
            .set('首次发现时间', 'firstFound')
            .set('最近发现时间', 'lastFound')
        return {
            api: slogIllegalSiteApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'houseName', title: '所在机房'}),
                new TableColumn({prop: 'ip', title: '应用IP'}),
                new TableColumn({prop: 'port', title: '端口',}),
                new TableColumn({prop: 'domain', title: '访问域名',}),
                new TableColumn({prop: 'accessCount', title: '访问次数'}),
                new TableColumn({prop: 'visitCount', title: '24小时访问量'}),
                new TableColumn({
                    prop: 'serviceContent',
                    title: '服务内容',
                    formatter: this.serviceContentFormats,
                }),
                new TableColumn({
                    prop: 'illegalType',
                    title: '违规情况',
                    formatter: this.illegalTypeFormat,
                }),
                new TableColumn({
                    prop: 'dealStatus',
                    title: '处置状态',
                    formatter: this.dealStatusFormat,
                }),
                new TableColumn({
                    prop: 'superviseCate',
                    title: '监测类型',
                    formatter: this.superviseCateFormat,
                }),
                new TableColumn({
                    prop: 'reportStatus',
                    title: '上报状态',
                    formatter: this.reportStatusFormat,
                }),
                new TableColumn({prop: 'operationAccount', title: '处置人'}),
                new TableColumn({prop: 'firstFound', title: '首次发现时间' ,formatter: TableColumn.datetimeFormat } ),
                new TableColumn({prop: 'lastFound', title: '最近发现时间' ,formatter: TableColumn.datetimeFormat }),
            ],

            /**
             * 服务内容列表
             */
            serviceContentlist:{ '500':'基础应用','501':'网络媒体','502':'电子政务、电子商务','503':'数字娱乐','504':'其他','1':'即时通信','2':'搜索引擎','3':'综合门户','4':'网上邮局','5':'网络新闻','6':'博客/个人空间','7':'网络广告/信息','8':'单位门户网站','9':'网络购物','10':'网上支付','11':'网上银行','12':'网上炒股/股票基金','13':'网络游戏','14':'网络音乐','15':'网络影视','16':'网络图片','17':'网络软件/下载','18':'网上求职','19':'网上交友/婚介','20':'网上房产','21':'网络教育','22':'网站建设','23':'WAP','24':'其他'},
            /**
             * 处置状态
             */
            dealStatuslist:{'0':'未处置','1':'已处置'},
            /**
             * 违法违规情况, 1：未备案 2：违法网站 999：其他
             */
            illegalTypelist:{'1':'未备案','2':'违法网站','999':'其他'},

            /**
             * 协议列表
             */
            protocolMap:[{"id":"1","name":"TCP"},{"id":"2","name":"UDP"},{"id":"3","name":"其他"}],

            /**
             * 处置状态
             */
            dealStatusMap:[{"id":"0","name":"未处置"},{"id":"1","name":"已处置"}],


            reportStatusMap: new Map().set(0, '未上报').set(1, '上报中').set(2, '已上报').set(3, '上报失败'),

            positions: [],


            /*上报信息*/
            msgInfo :'',
            /*上报数量*/
            reportNum :'',
            /*上报框是否显示*/
            isreportShow: false,
            /**
             * 批量处理显示
             */

            dealData:{},

            isTabhandleShow:false,

            /**
             * 处理结果 1:放行 2:屏蔽
             */
            dealResultStatus: 1,

            /**
             * 处理备注
             */
            dealmsg:'',

            /**
             * 1、处理 2、取消处理
             */
            dealStatusAction:1,
            superviseCateMap: new Map().set(1, '未备案').set(2, '黑名单'),
        }
    },
    methods: {
        createForm() {
            const data = forward.getData();
            return new IllegalSite({
                houseId: data.id,
                accessUrl: data.content,
            })
        },
        changeLastTime(timeArray) {
            [start, end] = timeArray || [];
            this.form.lastFoundTimeStart = start;
            this.form.lastFoundTimeEnd = end;
        },
        init() {
            this.initHouseMap();
        },
        initHouseMap: async function () {
            this.positions = await baseHouseInfoApi.selectList()
        },
        /**
         * 违法违规情况, 1：未备案 2：违法网站 999：其他,
         * @param row
         * @param column
         * @returns {String|*}
         */
        illegalTypeFormat: function (row, column) {
            return this.illegalTypelist[row.illegalType];
        },
        /**
         * 处置状态, 0: 未处置, 1: 已处置
         * @param row
         * @param column
         * @returns {String|*}
         */
        dealStatusFormat: function (row, column) {
            return this.dealStatuslist[row.dealStatus];
        },
        reportStatusFormat(row, column, val, key) {
            return this.reportStatusMap.get(val);
        },
        /**
         * 服务内容
         * @param row
         * @param column
         * @returns {String|*}
         */
        serviceContentFormats: function (row, column) {
            let Json = this.serviceContentlist;
            let key = row.serviceContent.split(",");
            let val = '';

            for (i in Json) {
                if (key.indexOf(i) > -1) {
                    if (val === '') {
                        val += Json[i]
                    } else {
                        val += ',' + Json[i]
                    }
                }
            }
            return val;

        },
        superviseCateFormat(row, cloumn, val, index) {
            return this.superviseCateMap.get(val);
        },
        reportShow() {
            //获取未上报的数据
            const dataList = this.selectedList.filter((obj) => parseInt(obj.reportStatus) == 0);
            this.selectedList = dataList;
            const length = dataList.length
            if (length > 0) {
                this.reportNum = length + '条,已上报的已忽略';
                this.isreportShow = true;
            } else {
                rxPrompt.msg('请勾选未上报的数据');
            }
        },
        /**
         * 确认上报
         * @returns {Promise.<void>}
         */
        report: async function () {
            const data = this.selectedList.filter((obj) => parseInt(obj.reportStatus) == 0);
            if (data.length > 0) {
                const reportData = {
                    data: data,
                    msgInfo: this.msgInfo,
                };
                const res = await slogIllegalSiteApi.reportData(reportData);
                if (res.code == 200) {
                    rxPrompt.msg("执行成功");
                    this.searchPage();
                } else {
                    rxPrompt.msg(`上报失败,${res.msg}`);
                }
            } else {
                rxPrompt.msg("没有上报的数据");
            }
            this.isreportShow = false;
        },
        /**
         * 重置确认上报
         */
        resetReport: function () {
            this.selectedIdList = [];
            this.mgInfo = '';
            this.reportNum = '没有符合规则日志';
        },
        /**
         * 处置提交
         */
        handleSub: async function () {
            const disposedData = this.selectedList.filter(obj => parseInt(obj.dealStatus) !== 0)
            if (disposedData.length !== 0) {
                await rxPrompt.msg('只能勾选未处置的数据');
                return;
            }
            if(!this.checkSelected()){
                return
            }
            const data = this.selectedList.filter(obj => parseInt(obj.dealStatus) === 0)
            this.dealData.data = data;
            this.dealData.msgInfo = this.dealmsg;
            this.dealData.dealUser = await sysLoginApi.currentUser().loginName;
            this.dealData.dealResultStatus = this.dealResultStatus;
            const res = await slogIllegalSiteApi.handle(this.dealData);
            if (res) {
                if (res.code == 200) {
                    await rxPrompt.msg('处置成功');
                    this.searchPage();
                    return;
                }
            }
            await rxPrompt.msg(`处置失败,${res.msg}`);
        },
        /**
         * 重置异常处理
         */
        resetTabhandle: function () {
            this.selectedList = [];
            this.dealmsg = '';
            this.dealResultStatus = 1;
        },
        /**
         * 取消处置
         */
        cancelHandle: async function () {
            const disposedData = this.selectedList.filter(obj => parseInt(obj.dealStatus) !== 1)
            if (disposedData.length !== 0) {
                await rxPrompt.msg('只能勾选已处置的数据');
                return;
            }
            if(!this.checkSelected()){
                return
            }
            const data = this.selectedList.filter(obj => parseInt(obj.dealStatus) === 1)
            this.dealData.data = data;
            this.dealData.msgInfo = '';
            this.dealData.dealUser = await sysLoginApi.currentUser().loginName;
            this.dealData.dealResultStatus = this.dealResultStatus;
            const res = await slogIllegalSiteApi.cancelHandle(this.dealData);
            if (res) {
                if (res.code == 200) {
                    await rxPrompt.msg('取消处置成功');
                    this.searchPage();
                    return;
                }
            }
            await rxPrompt.msg(`取消处置失败,${res.msg}`);
            this.searchPage();
        },
    },
    watch: {
        'form.protocol': async function (newVal, oldVal) {
            this.form.protocol=newVal;
        },

    },


})
